package com.linkoog.devtools.http.request.http_request.request_body.body;

import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.ui.components.JBTextField;
import com.linkoog.devtools.http.request.common.request_body.FileRequestBody;
import com.linkoog.devtools.http.request.http_request.request_body.BodyPanel;
import com.linkoog.devtools.intellij.ui.button.TextFieldWithBrowseButton;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

public class FileBodyPanel implements BodyPanel<FileRequestBody> {

    private JPanel myMainPanel;

    private JBTextField paramNameField;
    private TextFieldWithBrowseButton fileNameField;


    public FileBodyPanel() {

    }


    @Override
    public void resetRequestBody(@NotNull FileRequestBody requestBody) {
        paramNameField.setText(requestBody.getParamName());
        fileNameField.setText(requestBody.getFilePath());
    }

    @Override
    public @NotNull FileRequestBody buildRequestBody() {
        return FileRequestBody.of(paramNameField.getText(), fileNameField.getText(), fileNameField.getText());
    }

    @Override
    public JPanel getPanel() {
        return myMainPanel;
    }

    private void createUIComponents() {
        paramNameField = new JBTextField();
        JBTextField fileField = new JBTextField();

        fileNameField = new TextFieldWithBrowseButton();
        fileNameField.addBrowseFolderListener("选择文件", "选择文件", null, new FileChooserDescriptor(true, false, false, false, false, false));
    }
}
